authApp.value('page', 'expertDivision'); 
authApp.controller("chooseSub",function($scope,$http,$location,$getQueryString,Upload, $timeout,$sce,$cookieStore,$cookies){
	$scope.uploadFile="";
	$scope.uploadFiles= function(file, errFiles,index) {
        $scope.f = file;
        $scope.errFile = errFiles && errFiles[0];
        if (file) {
            file.upload = Upload.upload({
                url: apis.upload,
                data: {file: file}
            });

            file.upload.then(function (response) {
                $timeout(function () {
                	if(response.data.code=="000000"){
                		$scope.fileName=file.name;
                		$scope.uploadFile=response.data.data;
                	}
                	else
                		alert(response.data.errorMsg);
                });
            }, function (response) {
                if (response.status > 0)
                    $scope.errorMsg = response.status + ': ' + response.data;
            }, function (evt) {
                file.progress = Math.min(100, parseInt(100.0 * 
                evt.loaded / evt.total));
            });
        }
    }
	$scope.turnToDownLoad=function(){
		location.href=projectpath+"/static/file/expertFile.rar";
	}
	$scope.submitFile=function(){
		if($scope.uploadFile){
			$http({
				method:'post',
				url:apis.insertAuthSchoolExpertFile,
				data:{'expertid':$cookies.get("investigaPid"),'sid':$scope.schoolId,"filepath":$scope.uploadFile,"filename":$scope.fileName},
			}).success(function(response){
				if(response.code="000000"){
					alert("提交成功");
				}else{
					alert(response.errorMsg);
				}
			})
		}else{
			alert("请先上传文件");
		}
	}
	$http({
		method:'post',
		url:apis.querySchoolDataByExportId,
		data:{'pid':$cookies.get("investigaPid")},
	}).success(function(response){
		if(response.code="000000"){
			$scope.schoolName=response.data.schoolName;
			$scope.schoolId=response.data.pid;
			if(response.data.major=="1"){
				$scope.majorName="小学教育";
			}
			if(response.data.major=="0"){
				$scope.majorName="学前教育";
			}
			if(response.data.major=="2"){
				$scope.majorName="中学教育";
			}
			$http({
				method:'post',
				url:apis.queryAuthSchoolExpertFile,
				data:{'expertid':$cookies.get("investigaPid"),'sid':$scope.schoolId,},
			}).success(function(response){
				if(response.code="000000"){
					if(response.data[0]){
						$scope.fileName=response.data[0].filename;
					}
				}else{
					alert(response.errorMsg);
				}
			})
		}else{
			alert(response.errorMsg);
		}
	})
})